package com.example.yml;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class yuanmenglong0526 extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
    EditText et_name,et_pass;
    TextView tv_zc,tv_wjmm;
    CheckBox cb;
    Button butt_dl;
    boolean a=false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yuanmenglong0526);
        et_name=findViewById(R.id.et_name);
        et_pass=findViewById(R.id.et_pass);
        tv_zc=findViewById(R.id.tv_zc);
        cb=findViewById(R.id.cb);
        tv_wjmm=findViewById(R.id.tv_wjmm);
        butt_dl=findViewById(R.id.butt_dl);
        cb.setOnCheckedChangeListener(this);
        tv_zc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setClass(yuanmenglong0526.this,Main2Activity.class);
                startActivityForResult(intent,0);
                yuanmenglong0526.this.startActivity(intent);
            }
        });
        butt_dl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(a){
                    a=false;
                    Toast.makeText(yuanmenglong0526.this, "登入成功", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(yuanmenglong0526.this, "需要勾选记住密码才能登录", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==0){
           User user= (User) data.getSerializableExtra("name");
           String name=user.getName();
           String pass=user.getPass();
           et_name.setText(name);
           et_pass.setText(pass);
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        switch (compoundButton.getId()){
            case R.id.cb:
                if(b){
                   a=true;
                }
                break;
        }
    }
}
